<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use dosamigos\datetimepicker\DateTimePicker;
use common\helper\HashHelper;
/* @var $this yii\web\View */
/* @var $model common\models\MActivityShow */
/* @var $form yii\widgets\ActiveForm */
$time = time();
$key = HashHelper::getUploadHash($time);
?>
<style>
.field-mactivityshow-c_begin .input-group{width:300px;}
.field-mactivityshow-c_end .input-group{width:300px;}
</style>
<div class="mactivity-show-form">

    <?php $form = ActiveForm::begin(['id'=>'activity_show']); ?>
    <?= $form->field($model, 'c_name')->textInput(['maxlength' => true,'placeholder' => $model->getAttributeLabel('c_name')]) ?>

    <?= $form->field($model, 'c_sort')->textInput(['placeholder' => $model->getAttributeLabel('c_sort')]) ?>

    <?= $form->field($model, 'c_begin')->widget(DateTimePicker::className(), 
        [
        'template'=>"{input}{reset}{button}",
        'clientOptions' => [
            'autoclose' => true,
            'linkFormat' => 'yyyy-MM-dd HH:ii', // if inline = true
            // 'format' => 'HH:ii P', // if inline = false
            'todayBtn' => true,
            'minView' =>'hour',
            'pickerPosition'=>'bottom-left',
            'language'=>'zh-CN'
        ]    
])
    ?>
        <?= $form->field($model, 'c_end')->widget(DateTimePicker::className(), 
        [
        'template'=>"{input}{reset}{button}",
        'clientOptions' => [
            'autoclose' => true,
            'linkFormat' => 'yyyy-MM-dd HH:ii', // if inline = true
            //'format' => 'yyyy-mm-dd HH:ii', // if inline = false
            'todayBtn' => true,
            'minView' =>'hour',
            'pickerPosition'=>'bottom-left',
            'language'=>'zh-CN'
        ]    
])
    ?>

    <?= $form->field($model, 'c_status')->radioList(['下线','上线']) ?>

    <?= $form->field($model, 'c_content')->textarea(['rows' => 6,'placeholder' => $model->getAttributeLabel('c_content')]) ?>
    
    <?= $form->field($model,'c_image')->widget('yidashi\webuploader\Webuploader',['server'=>common\helper\UrlManager::createUrl(Yii::$app->params['domains']['upload'],['upload/webupload','time'=>$time,'key'=>$key])]); ?>
    
    <div class="form-group">
        <?= Html::submitButton('保存', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
<?php $this->beginBlock('js');?>
<script>
$(function(){

    <?php if($model->isNewRecord){?>
	$(".field-mactivityshow-c_image .help-block").html("<span style='color:red;font-size:13px;'>图片大小不超过2M,超过服务器最大设置，无反应</span>");
	<?php }?>
	
	$("#activity_show").submit(function(){

		var begin = $("#mactivityshow-c_begin").val();
		var end = $("#mactivityshow-c_end").val();
		if(!isEmpty(begin) && !isEmpty(end) ) {
			begin= begin.replace("-", "/").replace("-", "/");  
			end=  end.replace("-", "/").replace("-", "/");  
			var time1 = Date.parse(new Date(begin));
			var time2 = Date.parse(new Date(end));
			if(time1 > time2) {
				alert('结束时间不能小于开始时间');
				return false;
			}
		}
		return true;
	});	
	
});

function isEmpty(info){
	if(info==null||info==undefined||(""+info)==""){
		return true;
	}
	return false;
}
</script>
<?php $this->endBlock(); ?>
